package com.ctrip.ec.api.admin.controller.para;
import com.ctrip.ec.api.admin.model.query.QueryModel;
import com.ctrip.ec.dal.PagerSetting;
import com.ctrip.ec.api.admin.common.RequestContext;
import com.ctrip.ec.biz.dao.para.ParaDao;
import com.ctrip.ec.biz.entity.para.ParaEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;
@RestController
@RequestMapping("para")
public class ParaController{
    @Autowired
    private ParaDao para;
    @GetMapping("list")
    public List<ParaEntity> list() throws SQLException {
        List<ParaEntity> list = para.list();
        return list;
    }

    @PostMapping("list")
    public List<ParaEntity> list(@RequestBody QueryModel model) throws  SQLException{
        PagerSetting setting = model.build();
        List<ParaEntity> list = para.list(setting);
        RequestContext.setResponseHeaderCount(setting.getRecordCount());
        return list;
    }

    @GetMapping("detail/{id}")
    public  ParaEntity detail(@PathVariable Long id) throws SQLException {
        return para.entity(id);
    }

    @PostMapping("save")
    public  void save(@RequestBody ParaEntity entity) throws SQLException {
        para.save(entity);
    }

    @PostMapping("delete")
    public  void delete(@RequestBody List<Long> ids) throws SQLException {
        para.delete(ids);
    }
    @PostMapping("erase")
    public void erase(@RequestBody List<Long> ids) throws  SQLException{
        para.erase(ids);
    }

    @PostMapping("unerase")
    public  void unerase(@RequestBody List<Long> ids) throws  SQLException{
        para.unerase(ids);
    }
}
